<?php

namespace App\Http\Controllers\home\lilin;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;

use Illuminate\Http\Response;

use DB;

class orderController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        if(session('user')){
            
        }else{
            dd(222);
        }
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        //
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
       $order= $request->all();

       $food_id = $order['food_id'];
       $food_name = $order['food_name'];
       $num = $order['num'];

       $o_numbers = $_SERVER['REMOTE_ADDR']; 

        $order_status = 0;

       if($num==0){

            

            DB::table('orders')->where('menu_id',$food_id)->where('o_numbers',$o_numbers)->delete();

       }else{

            $yy = DB::table('orders')->where('o_numbers',$o_numbers)->where('menu_id',$food_id)->first();

            if($yy){
                DB::table('orders')
                ->where('menu_id', $food_id)->where('o_numbers',$o_numbers)
                ->update(['o_num' => $num,'o_price'=>$order['food_price']*$num]);
            }else{
                 DB::table('orders')->insert(['menu_id'=>$food_id,'o_num'=>$num,'o_price'=>$order['food_price']*$num,'o_numbers'=>$o_numbers,'order_status'=>$order_status,'food_name'=>$food_name]);
            }


       }

      $res = DB::table('orders')->where('o_numbers',$o_numbers)->get();
      

      return $res;

      




      
       

      
          
      
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        //
    }
}
